package com.itheima.app.cotroller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.VideoManager;
import com.itheima.domain.vo.PageBeanVo;
import org.apache.yetus.audience.InterfaceAudience;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;

    //查看列表
    @GetMapping("/smallVideos")
    public ResponseEntity findVideoByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        //1、获取userId
        Long userId = UserHolder.get().getId();
        //2、通过videoManager来传递
        PageBeanVo pageBeanVo = videoManager.findVideoByPage(userId, pageNum, pageSize);

        return ResponseEntity.ok(pageBeanVo);
    }

    //发布视频
    @PostMapping("/smallVideos")
    public void saveVideo(MultipartFile videoThumbnail , MultipartFile videoFile) throws IOException {
        Long userId = UserHolder.get().getId();
        videoManager.saveVideo(userId,videoThumbnail,videoFile);
    }
}
